package com.yeban.bams.mapper;

import com.yeban.bams.entity.Account;
import com.yeban.bams.entity.SavingAccount;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;

/**
 * 信用账户 数据操作
 */
public interface SavingAccountMapper {

    // 1.根据id和密码查询
    @Select("select acc_number as id, password, name, person_id as personId, email, balance, type from account where acc_number = #{id} and password = #{pwd}")
    public SavingAccount selectByIdAndPwd(@Param("id") Long id, @Param("pwd") String pwd);

    // 2.根据id查询
    @Select("select acc_number as id, password, name, person_id as personId, email, balance, type from account where acc_number = #{id}")
    public SavingAccount selectByAccountId(Long id);

    // 3.查询所有账户
    @Select("select acc_number as id, password, name, person_id as personId, email, balance, type from account")
    public List<SavingAccount> selectAll();

    // 4.添加账户
    @Insert("insert into account(acc_number, password, name, person_id, email, balance, type) " +
            "values(#{id}, #{password}, #{name}, #{personId}, #{email}, #{balance}, #{type})")
    public boolean insert(Account acc);

    // 5.更新账户
    @Update("update account set password=#{password}, name=#{name}, person_id=#{personId}, email=#{email}, balance=#{balance} where acc_number = #{id}")
    public boolean update(Account acc);
}
